﻿using black_screen_client.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace black_screen_client
{
    /// <summary>
    /// Interaction logic for MainControl.xaml
    /// </summary>
    public partial class MainControl : Window
    {
        MainWindow window;
        public MainCotrolData mcData =new MainCotrolData();
        LogRecord LogRecord = new LogRecord();
        public MainControl()
        {
            InitializeComponent();
            window = new MainWindow(this);
                ProjectTools.ShowWindow(window, Utils.ScreenPosition.Center);
                this.ImageIcon.DataContext = mcData;
                mcData.ImagePath = @".\Assets\redCtrl.png";

            //TODO：后续删掉
           // ProjectTools.ShowScreenInfo();

        }


        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            //让窗口显示或者隐藏到指定屏幕
            if(this.window.Visibility == Visibility.Collapsed)
            {
                ProjectTools.ShowWindow(window, Utils.ScreenPosition.Center);
                this.window.Visibility = Visibility.Visible;

            }
            else if(this.window.Visibility == Visibility.Visible)
            {
                this.window.Visibility = Visibility.Collapsed;
            }
        }

        private void Window_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
           
        }

        private void MenuItem_ShowBs(object sender, RoutedEventArgs e)
        {
            if (this.window.screen != null && this.window.screen.isBlackScreen == true)
            {
                ProjectTools.ShowWindow(this.window.screen, Utils.ScreenPosition.Center);
                this.window.screen.Visibility = Visibility.Visible;
            }
            else
            {
                System.Windows.MessageBox.Show("当前没有黑屏状态","提示");
            }
        }

        private void MenuItem_CloseBs(object sender, RoutedEventArgs e)
        {
            if (this.window.screen != null)
            {
                this.window.screen.Visibility = Visibility.Collapsed;
            }
        }
        private void MenuItem_OpenLog(object sender, RoutedEventArgs e)
        {
            if(this.LogRecord != null && this.LogRecord.Visibility != Visibility.Visible)
            {
                System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    this.LogRecord.RefreshLog();
                    this.LogRecord.LogGrid.ItemsSource = this.LogRecord.logs;
                    ProjectTools.ShowWindow(this.LogRecord, Utils.ScreenPosition.Center);
                    this.LogRecord.Visibility = Visibility.Visible;
                }));
               
            }
        }

        private void MenuItem_Exit(object sender, RoutedEventArgs e)
        {
            //关闭整个进程
            System.Environment.Exit(0);
        }
    }
}
